﻿
using Ross.Service;
using Ross.Service.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Http.Controllers;
using Ross.EntityFramework.Model;
using Ross.EntityFramework;

namespace Ross.Traning.Controllers
{
    [SimpleAuthenticationFilter]
    public class CourseClassController : BaseApiController
    {
        [HttpPost]
        public JsonResult<ResultDto<bool>> Insert([FromBody] Service.Dto.CourseClass vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (CourseClassService serv = new CourseClassService(dbContextStr))
            {
                result = serv.Create(vm);
            }
            return Json(result);
        }

        [HttpPost]
        public JsonResult<ResultDto<bool>> Update([FromBody] Service.Dto.CourseClass vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (CourseClassService serv = new CourseClassService(dbContextStr))
            {
                result = serv.Update(vm);
            }
            return Json(result);
        }

        [HttpPost]
        public JsonResult<ResultDto<bool>> Delete(int id) {
            ResultDto<bool> result = new ResultDto<bool>();
            using (CourseClassService serv=new CourseClassService(dbContextStr)) {
                result = serv.Delete(id);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.CourseClass>>> GetList() {
            ResultDto<List<Service.Dto.CourseClass>> result = new ResultDto<List<Service.Dto.CourseClass>>();
            using (CourseClassService serv = new CourseClassService(dbContextStr))
            {
                result = serv.GetAllList();
            }
            return Json(result);
        }

    }
}